home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / comm / thor / GMSignature.lha / GMSignature.thor.long < prev    next >
Encoding:
Text File  |  1999-10-21  |  4.9 KB  |  213 lines

  1. /*
  2. ** $VER: GMSignature.thor 0.002 (21.10.99)
  3. **       © Gian Maria Calzolari <gcalzo@geocities.com>
  4. **
  5. **  FUNCTION:
  6. **      Enhances Thor's signature systems implementing both a random tag
  7. **      and a specific conference's signature. Default signature allowed.
  8. **
  9. ** $HISTORY:
  10. **
  11. ** 21 Oct 1999 : 000.002 : Added pattern support for Conference name
  12. ** 20 Oct 1999 : 000.001 : First attempt, based from mine GMAutoWrite (try it! ;-)
  13. **
  14. */
  15.  
  16. parse upper arg "BBSNAME" BBS "CONFNAME" CNAME .
  17.  
  18. BBS   = strip(compress(BBS,'"'))
  19. CNAME = strip(compress(CNAME,'"'))
  20.  
  21. if BBS = "" | CNAME = "" then
  22.    call ExitMsg("GMSignature.thor must be called as Thor's Signature Command")
  23.  
  24. ConfigFile = 'ENV:Thor/' || BBS || '.cfg'
  25.  
  26. /* If no Configfile simply exit! */
  27. if ~Exists(ConfigFile) then
  28.    exit
  29.  
  30. VerStr     = subword(sourceline(2),3)
  31.  
  32. true  = 1
  33. false = 0
  34.  
  35. /* This tags can be omitted, default will be "blank" */
  36. TagOptsBlk = "TagPgm"
  37.  
  38. /* This tags can be omitted, default will be "zero" */
  39. TagOptsZro = "TagPgmType"
  40.  
  41. TagOptions = "SigFile" TagOptsBlk TagOptsZro
  42. NumOpts = words(TagOptions)
  43.  
  44. call ReadConfig
  45.  
  46. call Validate
  47.  
  48. index = SrcConf(CNAME)
  49.  
  50. if index = 0 then
  51.    index = SrcConf("DEFAULT")
  52.  
  53. if Exists(Tags.index.SIGFILE) then
  54.    address command 'type' Tags.index.SIGFILE
  55.   else
  56.    call ExitMsg("'SigFile' '" || Tags.index.SIGFILE || "' not found!")
  57.  
  58. if Tags.index.TAGPGM ~= '' then do
  59.    say "--"
  60.  
  61.    if Tags.index.TAGPGMTYPE = 0 then  /* Arexx */
  62.       Tags.index.TAGPGM
  63.      else                             /* dos   */
  64.       address command Tags.index.TAGPGM
  65. end
  66.  
  67. exit
  68.  
  69. /* ...game over... */
  70.  
  71.  
  72. Validate:
  73.    DefFound = false
  74.  
  75.    do i = 1 to Tags.0
  76.  
  77.       if upper(Tags.i) = "DEFAULT" then
  78.          DefFound = true
  79.  
  80.       do y = 1 to NumOpts
  81.          Opt = upper(word(TagOptions, y))
  82.          OptDef = symbol('Tags.i.Opt')
  83.  
  84.          Select
  85.              When find(upper(TagOptsBlk),Opt) > 0 then
  86.                if OptDef ~= 'VAR' then Tags.i.Opt = ''
  87.              When find(upper(TagOptsZro),Opt) > 0 then
  88.                if OptDef ~= 'VAR' then Tags.i.Opt = 0
  89.              Otherwise
  90.                if OptDef ~= 'VAR' then call ExitMsg("'" || Opt || "' not defined in tag '" || Tags.i || "'")
  91.          end
  92.  
  93.       end
  94.    end
  95.  
  96.    if ~DefFound then
  97.       call ExitMsg("'DEFAULT' tag not defined in file '" || ConfigFile || "'")
  98.  
  99. return
  100.  
  101.  
  102. /* Searches the conference in the config
  103. **  parm1   conference to be searched
  104. **
  105. **  returns the index or 0 if not found
  106. */
  107. SrcConf:
  108.    cnfr = arg(1)
  109.  
  110.    do i = 1 to Tags.0
  111.       CONF = cnfr
  112.  
  113.       if Tags.i.PAT = 0 then do
  114.  
  115.          if CONF = Tags.i then return i
  116.  
  117.         end
  118.         else do
  119.          select
  120.             when Tags.i.PAT = 1 then do
  121.                  CONF = left(CONF, length(Tags.i))
  122.  
  123.                  if CONF = Tags.i then return i
  124.  
  125.             end
  126.             when Tags.i.PAT = 2 then do
  127.                  CONF = right(CONF, length(Tags.i))
  128.  
  129.                  if CONF = Tags.i then return i
  130.  
  131.             end
  132.             when Tags.i.PAT = 3 then do
  133.  
  134.                  if index(CONF, Tags.i) > 0 then return i
  135.  
  136.             end
  137.          end
  138.       end
  139.    end
  140.  
  141. return 0
  142.  
  143.  
  144. ReadConfig:
  145.     /* Tags.0 will contains the Conference numbers, Tags.X will be the
  146.     **        Conference name (without the "*" if used...)
  147.     ** Tags.X.y will be defined as follow:
  148.     **     Tags.X.SigFile    File to be used as message sign
  149.     **     Tags.X.TagPgm     External pgm that will write a tag to stdout
  150.     **     Tags.X.TagPgmType External pgm type (0 = ARexx / 1 = dos)
  151.     **     Tags.X.Pat        internal field: 0=no pattern, 1=on right, 2=on left, 3=both
  152.     */
  153.     drop Tags.
  154.     Tags.0  = 0
  155.     TagsNum = 0
  156.  
  157.     CfgOpen = open(cfgfile,ConfigFile,'r')
  158.  
  159.     if ~(CfgOpen) then call ExitMsg('Reading: failed to open' ConfigFile)
  160.  
  161.     do until eof(cfgfile)
  162.         nextline = readln(cfgfile)
  163.  
  164.         if compress(nextline) = "" then iterate
  165.  
  166.         parse var nextline CfgName CfgVal
  167.         CfgName = upper(CfgName)
  168.         CfgVal  = strip(compress(CfgVal,'"'))
  169.  
  170.         if CfgName = 'TAG' then do
  171.            TagsNum = TagsNum + 1
  172.  
  173.            pattern = 0
  174.  
  175.            if right(CfgVal,1) = '*' then
  176.               pattern = pattern +1
  177.  
  178.            if left(CfgVal,1) = '*' then
  179.               pattern = pattern +2
  180.  
  181.            CfgVal = compress(CfgVal,'*')
  182.            Tags.TagsNum.PAT = pattern
  183.  
  184.            Tags.TagsNum = upper(CfgVal)
  185.          end
  186.          else do
  187.  
  188.            if TagsNum = 0 then call ExitMsg('No Tag names found!')
  189.  
  190.            if find(upper(TagOptions), CfgName) > 0 then
  191.               Tags.TagsNum.CfgName = CfgVal
  192.              else
  193.               call ExitMsg("Option '" || CfgName || "' (with value '" || CfgVal || "') in tag '" || Tags.TagsNum || "' not allowed!")
  194.         end
  195.     end
  196.  
  197.     if TagsNum = 0 then call ExitMsg('No Tag names found!')
  198.  
  199.     Tags.0 = TagsNum
  200.  
  201.     if (CfgOpen) then dummy = close(cfgfile)
  202. return
  203.  
  204.  
  205.  
  206. /* Exit with a message */
  207. ExitMsg:
  208.     parse arg msgstr
  209.     address command
  210.     'RequestChoice >NIL: "GMSignature.thor" "'msgstr'" "OK :-("'
  211. exit
  212.  
  213.